﻿$(function () {
    $.ajax({
        url: "/Personnel/PersonnelSummary/GetStatusSummary?ram" + Math.random(),
        type: "post",
        success: function (r) {
            var d = $.parseJSON(r);
            for (var i = 0; i < d.length; i++) {
                switch (d[i].Status) {
                    case "0":
                        $("#spanDws").text(d[i].Data);
                        break;
                    case "1":
                        $("#spanHszdsh").text(d[i].Data);
                        break;
                    case "2":
                        $("#spanHlbdsh").text(d[i].Data);
                        break;
                    case "3":
                        $("#spanHszbh").text(d[i].Data);
                        break;
                    case "4":
                        $("#spanYsh").text(d[i].Data);
                        break;
                    case "5":
                        $("#spanHlbbh").text(d[i].Data);
                        break;
                }
            }
        }
    });

    $(".addTab").on("click", function () {
        var url = $(this).attr("value");
        $(".menulink", window.parent.document.getElementById("accordion1")).each(function () {
            if ($(this).attr("taburl").indexOf("PersonnelReview/Index") != -1) {
                f_addTab($(this).attr("tabid"), $(this).attr("tabtext"), url);
                return false;
            }
        });
    });

    SummaryDisplay(1);
    SummaryDisplay(2);
});

function SummaryDisplay(type) {
    var divId = "echarts" + type;
    var myChart = echarts.init(document.getElementById(divId)); // 基于准备好的dom，初始化echarts实例

    var sTitle = "";
    if (type == "1") {
        sTitle = "职称分析表";
    }
    else if (type == "2") {
        sTitle = "能级分析表";
    }

    // 指定图表的配置项和数据
    var option = {
        title: { text: sTitle, subtext: "", x: 'center' },
        tooltip: { trigger: 'item', formatter: "{a} <br/>{b} : {c} ({d}%)" },
        legend: { orient: 'vertical', x: 'left', data: [] },
        toolbox: {
            show: true,
            x: 'right',
            padding: [0, 20, 0, 0],
            feature: {
                mark: { show: false },
                dataView: { show: false, readOnly: false },
                magicType: {
                    show: true,
                    type: ['pie', 'funnel'],
                    option: {
                        funnel: {
                            x: '25%', width: '50%',
                            funnelAlign: 'left',
                            max: 1548
                        }
                    }
                },
                restore: { show: true },
                saveAsImage: { show: true }
            }
        },
        calculable: true,
        series: [{
            name: '访问来源',
            type: 'pie',
            radius: '55%',
            center: ['60%', '60%'],
            data: []
        }]
    };

    $.ajax({
        url: "/Personnel/PersonnelSummary/GetPersonnelAnalysis?type=" + type + "&ram" + Math.random(),
        cache: false,
        success: function (r) {
            var d = $.parseJSON(r);
            var legendData = [];
            var seriesData = [];
            for (var i = 0; i < d.length; i++) {
                legendData.push(d[i].Name);
                seriesData.push({ value: d[i].Data, name: d[i].Name });
            }
            option.legend.data = legendData;
            option.series[0].data = seriesData;
            myChart.setOption(option);
        }
    });
}